//添加论坛问题回答且更新回答数
exports.au_forum_content_answer = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;
    //最终结果
    var resultData = {};

    var forumCommentAnswerData = 0;
    //任务流创建
    async.waterfall([
            //1.权限验证
            /*function (cb) {
                P.permissionValidation(req, res, [CORE_APIConfig.coreAPI.addContentAnswer], function () {
                    cb()
                });
            },*/
            //1.添加回答记录
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.addContentAnswer,
                        method: 'POST',
                        data: {
                            fca_uid: bodyParams.fca_uid,
                            fca_content: bodyParams.fca_content,
                            fcc_fcid: bodyParams.fcc_fcid,
                            fca_images: bodyParams.fca_images == undefined ? "" : bodyParams.fca_images
                        }
                    },
                    function (err, data) {
                        // //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }
                        resultData.addData = data;
                        cb();
                    }
                );
            },
            //查询回答数量
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_question + "/fc_id/" + bodyParams.fcc_fcid,
                        method: 'POST',
                        data: {
                            fields: ["fc_id", "fc_answer_count"].join(",")
                        }
                    },
                    function (err, data) {
                        //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        forumCommentAnswerData = data.data;
                        cb();
                    }
                );

            },
            //3.论坛问题回答数量更新
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.updateContent,
                        method: 'POST',
                        data: {
                            fc_id: bodyParams.fcc_fcid,
                            fc_answer_count: parseInt(forumCommentAnswerData[0].fc_answer_count) + 1
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        resultData.updateData = data;
                        cb();
                    }
                );

            },
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}